<cfcomponent output="false">


	<cffunction name="auth" access="public">
		<cfargument name="myFusebox" />
		<cfargument name="event" />
		<cfset var local = StructNew() />
		<cfset event.xfa("login","app.login") />
		<cfset local.oUser = myFusebox.getApplication().getApplicationData().servicefactory.getBean("User") />
		<cfset local.oUser.setUsername(arguments.event.getValue("j_username")) />
		<cfset local.blnIsUserLoaded = local.oUser.load() />
		<cfif (local.blnIsUserLoaded)>
			<cfset local.blnAuthSuccess = local.oUser.authenticate(arguments.event.getValue("j_password")) />
			<cfif (local.blnAuthSuccess)>
				<cflock scope="Session" type="exclusive" timeout="4">
					<cfset session.oUser = local.oUser />
					<cflogin>
						<cfloginuser name="#session.oUser.getUsername()#" password="#Hash(arguments.event.getValue('j_password'))#" roles="administrator" />
					</cflogin>
				</cflock>
			<cfelse>
				<cfset arguments.myFusebox.relocate(xfa="login") />
			</cfif>
		<cfelse>
			<cfset arguments.myFusebox.relocate(xfa="login") />
		</cfif>
	</cffunction>


	<cffunction name="deauth" access="public" hint="Ensures the termination of the privelaged authenticated session.">
		<cfargument name="myFusebox" />
		<cfargument name="event" />
		<cfif (StructKeyExists(session, "oUser"))>
			<cfset session.oUser.setIsAuthenticated(false) />
		</cfif>
		<cflogout />
	</cffunction>


</cfcomponent>